package si.banst.tecajnice.entitete;

import static javax.persistence.EnumType.STRING;
import static javax.persistence.TemporalType.TIMESTAMP;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.NamedQuery;
import javax.persistence.Column;
import javax.persistence.NamedQueries;

@Entity
@NamedQueries({
		@NamedQuery(name = "vrniVseTecaje", query = "SELECT t FROM Tecaj t"),
		@NamedQuery(name = "vrniVseNeaktivneTecaje", query = "SELECT t FROM Tecaj t WHERE t.statusAktivnosti = si.banst.tecajnice.entitete.StatusAktivnosti.NEAKTIVEN") })
public class Tecaj implements Serializable {
	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private TecajID id;

	@Temporal(TIMESTAMP)
	private Date datumCasSpremembe;

	private BigDecimal enotaTecaja;

	@Column(scale = 4, precision = 24)
	private BigDecimal nakupniTecaj;

	@Column(scale = 4, precision = 24)
	private BigDecimal prodajniTecaj;

	@Column(scale = 4, precision = 24)
	private BigDecimal srednjiTecaj;

	@Enumerated(STRING)
	private StatusAktivnosti statusAktivnosti;

	@ManyToOne
	private Tecajnica tecajnica;

	@ManyToOne(fetch = FetchType.EAGER)
	private Valuta valuta;

	private String referent;

	public Tecaj() {
		super();
	}

	public TecajID getId() {
		return id;
	}

	public void setId(TecajID id) {
		this.id = id;
	}

	public Date getDatumCasSpremembe() {
		return datumCasSpremembe;
	}

	public void setDatumCasSpremembe(Date datumCasSpremembe) {
		this.datumCasSpremembe = datumCasSpremembe;
	}

	public BigDecimal getEnotaTecaja() {
		return enotaTecaja;
	}

	public void setEnotaTecaja(BigDecimal enotaTecaja) {
		this.enotaTecaja = enotaTecaja;
	}

	public BigDecimal getNakupniTecaj() {
		return nakupniTecaj;
	}

	public void setNakupniTecaj(BigDecimal nakupniTecaj) {
		this.nakupniTecaj = nakupniTecaj;
	}

	public BigDecimal getProdajniTecaj() {
		return prodajniTecaj;
	}

	public void setProdajniTecaj(BigDecimal prodajniTecaj) {
		this.prodajniTecaj = prodajniTecaj;
	}

	public BigDecimal getSrednjiTecaj() {
		return srednjiTecaj;
	}

	public void setSrednjiTecaj(BigDecimal srednjiTecaj) {
		this.srednjiTecaj = srednjiTecaj;
	}

	public StatusAktivnosti getStatusAktivnosti() {
		return statusAktivnosti;
	}

	public void setStatusAktivnosti(StatusAktivnosti statusAktivnosti) {
		this.statusAktivnosti = statusAktivnosti;
	}

	public String getReferent() {
		return referent;
	}

	public void setReferent(String referent) {
		this.referent = referent;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Tecaj))
			return false;
		Tecaj other = (Tecaj) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public Tecajnica getTecajnica() {
		return tecajnica;
	}

	public void setTecajnica(Tecajnica tecajnica) {
		this.tecajnica = tecajnica;
	}

	public Valuta getValuta() {
		return valuta;
	}

	public void setValuta(Valuta valuta) {
		this.valuta = valuta;
	}

	@Override
	public String toString() {
		return "Tecaj [id=" + id + ", datumCasSpremembe=" + datumCasSpremembe
				+ ", enotaTecaja=" + enotaTecaja + ", nakupniTecaj="
				+ nakupniTecaj + ", prodajniTecaj=" + prodajniTecaj
				+ ", srednjiTecaj=" + srednjiTecaj + ", statusAktivnosti="
				+ statusAktivnosti + ", tecajnica=" + tecajnica + ", valuta="
				+ valuta + ", referent=" + referent + "]";
	}

}